function [datm1,datm2,handvec,sernames,legcell]=compare_data(dfname1,dpath1,dfname2,dpath2,sernames)
% =========================================================================
% COMPARE_DATA 
% function [datm1,datm2,handvec,sernames,legcell]=compare_data(dfname1,dpath1,dfname2,dpath2,sernames)
% AJ June 22 2009 
cucd=cd; 
cd(dpath1); 
[datm1,ser1]=xlsread(dfname1); 
cvec1=datm1(:,1); 
datm1=datm1(:,2:end); 
if nargin <= 3 || isempty(dpath2); 
    dpath2=dpath1;
end     
cd(dpath2); 
[datm2,ser2]=xlsread(dfname2); 
cvec2=datm2(:,1); 
datm2=datm2(:,2:end); 
cd(cucd); 

[cvec,rows1,rows2]=intersect(cvec1,cvec2); 
datm1=datm1(rows1,:); 
datm2=datm2(rows2,:); 
if any( size(datm1)-size(datm2) ~= 0); 
    error('Sizes do not match'); 
end 
if isempty(sernames); 
    sernames=ser1; 
end 
legcell={dfname1,dfname2};
handvec=zeros(7,1); 
for ii=1:7; 
    figure; 
    plot2samp(cvec,[datm1(:,ii) datm2(:,ii)]); 
    temp=corrcoef( [datm1(:,ii) datm2(:,ii)]    ); 
    temp=num2str(temp(2,1),3); 
    legend(legcell{1},legcell{2}); 
    title([sernames{ii},': in ',legcell{1},' and ',legcell{2},'   correlation=',temp ]); 
    handvec(ii)=gcf; 
end 
